<template>
    <div class="product-container">
        <div class="container">
            <div class="left">
                <div class="box">
                    <div>
                        <img style="width:420px ;height: 420px;" :src="this.itemDetail.imgList[currentImageIndex]"
                            alt="Product Image">
                    </div>
                    <div class="pics">
                        <div class="left-icon-box">
                            <img @click="prevImage(index)" src="../../public/img/icons/向左箭头.png" alt=""
                                class="left-icon">
                        </div>

                        <img v-for="item, index in this.itemDetail.imgList" :key="index" @click="picIndex(index)" :src="item" alt=""
                            :class="['pic-item ', { borderactive: borIndex === index }]">

                        
                        <div class="right-icon-box">
                            <img @click="nextImage(index)" src="../../public/img/icons/向右箭头.png" alt=""
                                class="right-icon">
                        </div>
                    </div>
                    <div class="product-text">
                        <p class="other-infoCoding">商品编码:AG4GOK01DU1BA3 </p>
                        <p class="onsell-collect">
                            <img src="" alt="">
                            收藏商品
                        </p>
                        <button class="pi-share-box">分享到</button>
                    </div>
                    <div class="pi-promise-box">
                        <img src="//shop.vipstatic.com/img/detail/pc_xuanguan-hash-0c8f754a.png" alt="">
                    </div>
                </div>

            </div>
            <div class="right">
                <div class="pib-title">
                    DAZZLE
                </div>
                <div class="pib-vendo-shop">
                    <div class="pib-vendor-vipsale">唯品自营</div>
                    <div class="pib-title-detail">{{ this.itemDetail.text }}</div>
                </div>
                <div class="spcecialPrice-box">
                    <div class="price-v6-line-one">
                        <span>¥</span>{{ this.itemDetail.newPrice }}
                    </div>
                    <div class="price-v6-line-two">
                        <span class="price-v6-line-two-one">¥{{ this.itemDetail.oldPrice }}</span>
                        <span class="price-v6-line-two-two">4.0折</span>
                    </div>
                </div>
                <template>
                    <span class="c-delivery-address-name">
                        配送
                    </span>
                    <el-select v-model="label" placeholder="请选择省市区" class="custom-select">
                        <el-option-group v-for="group in options" :key="group.label" :label="group.label">
                            <el-option v-for="item in group.options" :key="item.value" :label="item.label"
                                :value="item.label">
                            </el-option>
                        </el-option-group>
                    </el-select>
                </template>
                <div class="i-freight">
                    <span class="freight-name">运费</span>
                    <p class="freight_tips">新会员专享首单满38元免邮（限唯品自营商品，部分商品不可用）</p>
                </div>
                <div class="i-color">
                    <span class="color-name">颜色</span>
                    <div class="color-list">
                        <div v-for="(item, index) in this.itemDetail.colorList" :key="index"
                            :class="['color-list-item', { active: colcrIndex === index }]" @click="selectColor(index)">
                            {{ item.color }}
                        </div>
                    </div>
                </div>
                <div class="i-size clearfix J-sizeArea-wrap ">
                    <span class="size-name">尺码</span>
                    <div class="size-list">
                        <div v-for="(item, index) in this.itemDetail.sizeList" :key="index"
                            :class="['size-list-item', { active1: sizeindex === index }]" @click="selectSize(index)">
                            {{ item.siz }}
                        </div>
                    </div>
                </div>
                <div class="J_sizeTips_input size-list-tips">录入您的尺码信息，精准推荐尺码：<span
                        class="J_size_helper_trigger_btn">录入尺码信息</span>
                </div>
                <template>
                    <span class="num-name">数量</span>
                    <el-input-number v-model="num" @change="handleChange" :min="1" :max="10" label="描述文字"
                        class="num"></el-input-number>
                </template>
                <div class="i-button">
                    <div class="comparePrice">¥{{ this.itemDetail.oldPrice }}</div>
                    <div class="finalPrice">
                        <div class="i-price">¥{{ this.itemDetail.newPrice }}</div>
                    </div>
                    <div @click="addcart()"
                        style="background-color: #fd3e6f; height: 44px; line-height: 44px; color: #fff; font-weight: bold;margin-left: 100px; padding: 0 10px;">
                        加入购物车
                    </div>
                </div>
                <div class="other">
                    <span class="other-name">服务</span>
                    <div class="other-box">
                        <div class="services-wrap">
                            <div class="iconType iconSuccess">
                                <img src="../../public/img/icons/选中.png" alt="">
                            </div>
                            <div class="services">首单38元免邮</div>
                        </div>
                        <div class="services-wrap">
                            <div class="iconType iconSuccess">
                                <img src="../../public/img/icons/选中.png" alt="">
                            </div>
                            <div class="services">10天价保</div>
                        </div>
                        <div class="services-wrap">
                            <div class="iconType iconSuccess">
                                <img src="../../public/img/icons/选中.png" alt="">
                            </div>
                            <div class="services">极速退款</div>
                        </div>
                        <div class="services-wrap">
                            <div class="iconType iconSuccess">
                                <img src="../../public/img/icons/选中.png" alt="">
                            </div>
                            <div class="services">上门退货</div>
                        </div>
                        <div class="services-wrap">
                            <div class="iconType iconSuccess">
                                <img src="../../public/img/icons/选中.png" alt="">
                            </div>
                            <div class="services">破损无忧</div>
                        </div>
                        <div class="services-wrap">
                            <div class="iconType iconSuccess">
                                <img src="../../public/img/icons/选中.png" alt="">
                            </div>
                            <div class="services">15天质量无忧</div>
                        </div>
                        <div class="services-wrap">
                            <div class="iconType iconSuccess">
                                <img src="../../public/img/icons/选中.png" alt="">
                            </div>
                            <div class="services">7天无理由退货</div>
                        </div>
                        <div class="services-wrap">
                            <div class="iconType iconSuccess">
                                <img src="../../public/img/icons/选中.png" alt="">
                            </div>
                            <div class="services">7天可换</div>
                        </div>
                        <div class="services-wrap">
                            <div class="iconType iconSuccess">
                                <img src="../../public/img/icons/选中.png" alt="">
                            </div>
                            <div class="services">唯品会发货</div>
                        </div>
                        <div class="services-wrap">
                            <div class="iconType iconSuccess">
                                <img src="../../public/img/icons/选中.png" alt="">
                            </div>
                            <div class="services">正规发票</div>
                        </div>
                        <div class="services-wrap">
                            <div class="iconType iconSuccess">
                                <img src="../../public/img/icons/选中.png" alt="">
                            </div>
                            <div class="services">唯爱心公益计划</div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</template>
<script>
import { detail } from '@/request/api/all'
export default {
    data() {
        return {
            itemDetail: {},
            colcrIndex: 0, // 默认选中第一个,
            sizeindex: 0,
            borIndex: 0,
            currentImageIndex: 0,
            num: 1,
            options: [{
                label: '热门城市',
                options: [{
                    value: 'Shanghai',
                    label: '上海市'
                }, {
                    value: 'Beijing',
                    label: '北京市'
                }]
            }, {
                label: '城市名',
                options: [{
                    value: 'Chengdu',
                    label: '成都市'
                }, {
                    value: 'Shenzhen',
                    label: '深圳市'
                }, {
                    value: 'Guangzhou',
                    label: '广州市'
                }, {
                    value: 'Dalian',
                    label: '大连市'
                }]
            }],
            label: '',
            arr: [],
            obj:{}
        }
    },
    methods: {
        handleChange(value) {
            console.log(value);
        },
        selectColor(index) {
            this.colcrIndex = index; // 更新选中的索引
        },
        selectSize(index) {
            this.sizeindex = index
        },
        prevImage() {
            this.currentImageIndex--;
            this.borIndex--;
            if (this.currentImageIndex < 0 || this.borIndex < 0) {
                this.currentImageIndex = this.itemDetail.imgList.length - 1;
                this.borIndex = this.itemDetail.imgList.length - 1;
            }
        },
        nextImage() {
            this.currentImageIndex++;
            this.borIndex++;
            if (this.currentImageIndex >= this.itemDetail.imgList.length || this.borIndex >= this.itemDetail.imgList.length) {
                this.currentImageIndex = 0;
                this.borIndex = 0;
            }
        },
        picIndex(index) {
            this.currentImageIndex = index
            this.borIndex = index
        },
        async detail1() {
            console.log(1111);
            const itemId = this.$route.params.itemId;
            console.log('id', itemId);
            let res = await detail('/getShoe')
            console.log(res.data.data[0].data);
            // console.log("res", res.data.data[0])
            let data = res.data.data[0].data.find((item) => item.id === itemId)
            console.log('data', data);
            this.itemDetail = data
            console.log('detail', this.itemDetail);
        },
        addcart() {
            this.obj = {
                id:this.arr.length,
                name: this.itemDetail.text,
                pic: this.itemDetail.imgList[this.currentImageIndex],
                color: this.itemDetail.colorList[this.colcrIndex],
                size: this.itemDetail.sizeList[this.sizeindex],
                count: this.num,
                price: this.itemDetail.newPrice,
                itemPrice: this.itemDetail.newPrice,
                Allprice: this.itemDetail.newPrice * this.num,
                visible:false,
                checked:true
            }
            this.arr.push(this.obj)
            console.log('arr', this.arr);
            this.$router.push({
                name: 'cart',
                params: { array: this.arr,title: this.label }
            });
        }
    },
    mounted() {
        this.detail1()
    }
}
</script>
<style scoped>
ul,
li {
    list-style: none;
}

.container {
    width: 1280px;
    margin: 0 auto;
    display: flex;
}

.pic {
    width: 420px;
    height: 420px;
}

.box {
    width: 420px;
    left: 390px;
    top: 430px;

}

.left-icon-box,
.right-icon-box {
    width: 29px;
    height: 64px;
    line-height: 40px;
    background-color: #ddd;
}

.left-icon,
.right-icon {
    width: 16px;
    height: 16px;
}

.pics {
    width: 420px;
    display: flex;
    justify-content: space-between !important;
    margin-top: 10px;
}

.pics .pic-item {
    width: 62px;
    height: 62px;
}

.product-text {
    width: 420px;
    padding-bottom: 10px;
    border-bottom: 1px dashed #ccc;
    display: flex;
    justify-content: space-between;
    margin-top: 20px;
}

.other-infoCoding {
    color: #999;
    line-height: 20px;
    display: inline-block;
    font-size: 12px;
    text-overflow: ellipsis;
    white-space: nowrap;
    overflow: hidden;
    max-width: 200px;
}

.onsell-collect {
    line-height: 16px;
    cursor: pointer;
    width: 70px;
    padding: 1px 0 1px 2px;
    display: inline-block;
    font-size: 12px;
    margin-left: 18px;
    vertical-align: top;
}

.pi-share-box {
    width: 95px;
    height: 24px;
    font-size: 12px;
    margin-top: 10px;
}

.right {
    width: 550px;
    margin-left: 20px;
}

.pib-title {
    width: 550px;
    color: #007cff;
    text-overflow: ellipsis;
    font-size: 16px;
    cursor: pointer;
    line-height: 22px;
    min-height: 22px;
    text-align: left;

}

.pib-vendo-shop {
    display: flex;
    margin-bottom: 10px;
}

.pib-vendor-vipsale {
    height: 18px;
    font-family: MicrosoftYaHei;
    font-size: 12px;
    color: #fff;
    font-weight: 400;
    padding: 2px 4px 2px 4px;
    margin: 8px 10px 0 0;
    background-color: #fd3e6f;
}

.pib-title-detail {
    font-size: 16px;
    color: #333;
    max-height: 40px;
    overflow: hidden;
    line-height: 20px;
    margin-top: 8px;
    margin-bottom: 8px;
    font-weight: 700;
}

.spcecialPrice-box {
    width: 550px;
    background-color: #fd3e6f;
    margin-bottom: 20px;
}

.price-v6-line-one {
    height: 50px;
    padding-top: 10px;
    font-size: 38px;
    font-family: arial;
    max-width: 100px;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
    -webkit-box-align: baseline;
    color: #fff;
    font-weight: 700;
}

.price-v6-line-one span {
    font-size: 24px !important;
}

.price-v6-line-two {
    color: #fff;
    font-size: 16px;
    max-width: 120px;
    padding-bottom: 10px;
}

.price-v6-line-two-one {
    text-decoration: line-through;
    margin-right: 10px;
}

.c-delivery-address-name {
    font-size: 12px;
    width: 40px;
    text-align: left;
    color: #999;
    line-height: 32px;
    overflow: hidden;
    text-align: left;
}

.custom-select {
    width: 250px;
    height: 30px;
    line-height: 30px;
    margin-right: 250px;
    margin-left: 20px;
}

.i-freight {
    width: 550px;
    font-size: 12px;
    display: flex;
    height: 32px;
    line-height: 30px;
    margin-top: 10px;
    margin-bottom: 20px;
}

.freight-name {
    width: 40px;
    text-align: left;
    color: #999;
    line-height: 32px;
    overflow: hidden;
    text-align: left;
}

.freight_tips {
    margin-left: 10px;
}

.i-color {
    width: 550px;
    display: flex;
}

.color-name {
    font-size: 12px;
    width: 50px;
    text-align: left;
    color: #999;
    line-height: 32px;
    overflow: hidden;
}

.color-list {
    display: flex;
    flex-wrap: wrap;
}

.color-list-item {
    width: 105px;
    height: 32px;
    line-height: 32px;
    text-align: center;
    border: 2px solid #ddd;
    font-size: 12px;
    margin-right: 20px;
    margin-bottom: 10px;
}

.i-size {
    display: flex;

}

.size-name {
    font-size: 12px;
    width: 40px;
    text-align: left;
    color: #999;
    line-height: 32px;
    overflow: hidden;
}

.size-list {
    display: flex;
    margin-left: 10px;
}

.size-list-item {
    padding: 0 10px;
    line-height: 30px;
    text-align: center;
    border: 1px solid #ddd;
    margin-right: 20px;
    font-size: 12px;
}

.size-list-tips {
    font-size: 12px;
    color: #f40080;
    margin-bottom: 15px;
}

.J_size_helper_trigger_btn {
    cursor: pointer;
    color: #007cff;
    font-size: 12px;

}

.num-name {
    font-size: 12px;
    width: 40px;
    text-align: left;
    color: #999;
    line-height: 32px;
    overflow: hidden;
    /* text-align: left; */
}

.num {
    width: 175px;
    height: 30px !important;
    margin-right: 325px;
    margin-left: 25px;
}

.i-button {
    display: flex;
    height: 46px;
    margin-left: 50px;
    margin-top: 20px;
    margin-bottom: 20px;
}

.comparePrice {
    width: 113px;
    height: 44px;
    background-color: #f688a4;
    color: #fff;
    text-decoration: line-through;
    line-height: 44px;
    text-align: center;
    font-size: 20px;
    font-weight: bold;
}

.finalPrice {
    width: 137px;
    height: 44px;
    line-height: 44px;
    text-align: center;
    color: #fff;
    background-color: #fd3e6f;
    font-size: 20px;
    font-weight: bold;
}

.other {
    width: 550px;
    /* margin-top: 200px; */
    display: flex;
}

.other-name {
    font-size: 12px;
    width: 40px;
    text-align: left;
    color: #999;
    line-height: 32px;
    overflow: hidden;
}

.iconType img {
    width: 16px;
    height: 16px;
}

.services {
    font-size: 12px;
    color: #666;
}

.services-wrap {
    display: flex;
    margin-right: 15px;
}

.other-box {
    width: 500px;
    display: flex;
    flex-wrap: wrap;
    margin-left: 10px;
    margin-top: 5px;
}

.active {
    border: 2px solid #fd3e6f;
}

.active1 {
    border: 2px solid #fd3e6f;
}

.borderactive {
    border: 2px solid #fd3e6f;
}
</style>